/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 13754
 * @create 2023/12/3
 * @since 1.0.0
 */
package com.mengniu.commerce.common.core.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 *
 * @author 13754
 * @Date 2023/12/3 12:08
 * @Version 1.0.0
 */
@Slf4j
public class Utf8DecoderUtils {

    public static String UTF8Decoder(String utf8String){
        String decodedString ="";
        try {
            // 进行URL解码
            String decodedJson = URLDecoder.decode(utf8String, "UTF-8");

            // 将JSON字符串反序列化为Java对象
            ObjectMapper objectMapper = new ObjectMapper();
            decodedString = objectMapper.readValue(decodedJson, Object.class).toString();

            log.info("解码后的结果为:{}",decodedString);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  decodedString;
    }

}
